package com.waitingresult.designpattern.creation.singleton.type7_static_interior_clas;


public class SingletonDemo {
    public static void main(String[] args) {
        new Thread(new SingletonThread()).start();
        new Thread(new SingletonThread()).start();
        new Thread(new SingletonThread()).start();
        new Thread(new SingletonThread()).start();
        new Thread(new SingletonThread()).start();

    }
}

class SingletonThread implements Runnable {
    @Override
    public void run() {
        System.out.println(Singleton.getInstance());
    }
}

class Singleton {
    //私有构造
    private Singleton() {
    }

    //提供一个获取实例的方法
    public static Singleton getInstance() {
        return NewSingleton.INSTANCE;
    }

    //写一个 静态的内部类
    private static class NewSingleton {
        private static final Singleton INSTANCE = new Singleton();
    }
}
